﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using EbbinghausWord.BLL;
using Microsoft.Phone.Controls;

namespace EbbinghausWord.Pages
{
    public partial class ScorePage : PhoneApplicationPage
    {
        public ScorePage()
        {
            InitializeComponent();

            double score = 0f;
            int totalScore = 0;
            string bookName = "";
            double todayScore = 0f;
            List<ScoreEntity> scores = null;

            loadingControl.Loading(
                () =>
                {
                    ScoreManager.InitScore();
                    score = ScoreManager.GetCurrentScore();
                    totalScore = ScoreManager.GetCurrentBookTotalScore();
                    bookName = WordBookManager.GetCurrentBook().BookName;
                    scores = ScoreManager.Scores.OrderByDescending(x => x.Date).ToList();
                    todayScore = double.Parse(scores[0].Score) - double.Parse(scores[1].Score);
                },
                    () =>
                    {

                        totalScoreTextBlock.Text = string.Format("总分：{0}", totalScore);
                        isLeanringBookTextBlock.Text = string.Format("正在学习：{0}", bookName);

                        todayScoreTextBlock.Text = todayScore.ToString("0.0");
                        currentScoreTextBlock.Text = score.ToString("0.0");
                        completeRatioTextBlock.Text = (score / totalScore * 100).ToString("0.000");

                        scoreListBox.ItemsSource = scores;
                    });
        }


    }
}